package top.blackr.folivora.config;

import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;

/**
 * 容器使用虚拟线程
 */
@Configuration
public class SpringVirtualThreadConfig {

    /**
     * undertow请求使用虚拟线程
     *
     * @return UndertowDeploymentInfoCustomizer
     */
    @Bean
    public UndertowDeploymentInfoCustomizer undertowDeploymentInfoCustomizer() {
        return deploymentInfo -> deploymentInfo.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
    }
}
